<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle"></TopFilter>
    <BreakSpace label="潜客列表" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="table"
      selectionType="single"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button @click="closeDialog(1)">关 闭</el-button>
      <el-button @click="closeDialog(2)" :disabled="isDisabled" type="primary">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';

import { queryPotentialCustomer } from '@/api/dealerSale/SalesSanagement/RetailOrderMaintenanceAF';

export default {
  mixins: [dictionary],

  data() {
    this.saveData = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryPotentialCustomer,
      fetchParams: {},
      isDisabled: true
    };
  },
  created() {},
  methods: {
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    closeDialog(type) {
      if (type == 1) {
        this.$emit('close', false);
      } else {
        if (this.saveData[0].clueRecordId) {
          this.$confirm('此客户已有线上的订单，请确认是否要生成线下订单?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '关闭',
            type: 'warning'
          }).then(() => {
            this.$emit('close', false, this.saveData);
          });
          return;
        }
        this.$emit('close', false, this.saveData);
      }
    },
    selectChangeHandle(row) {
      console.log(row, '---选择潜客---');
      if (row.length > 0) {
        this.isDisabled = false;
        this.saveData = row;
        return;
      }
      this.isDisabled = true;
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'potentialCustomerName',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '手机号',
          fieldName: 'potentialCustomerPhone',
          placeholder: '请输入'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '客户编号',
          dataIndex: 'potentialCustomerNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '性别',
          dataIndex: 'gender',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1002'),
          render: props => {
            return <span>{this.createDictText(props.row.gender, '1002')}</span>;
          }
        },
        {
          title: '手机号',
          dataIndex: 'mobilePhone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户类型',
          dataIndex: 'customerType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1523'),
          render: props => {
            return <span>{this.createDictText(props.row.customerType, '1523')}</span>;
          }
        },
        {
          title: '意向级别',
          dataIndex: 'intentLevel',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1519'),
          render: props => {
            return <span>{this.createDictText(props.row.intentLevel, '1519')}</span>;
          }
        },
        {
          title: '客档状态',
          dataIndex: 'clueStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('7000'),
          render: props => {
            return <span>{this.createDictText(props.row.clueStatus, '7000')}</span>;
          }
        },
        {
          title: '证件类型',
          dataIndex: 'ctCode',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1508'),
          render: props => {
            return <span>{this.createDictText(props.row.ctCode, '1508')}</span>;
          }
        },
        {
          title: '证件号码',
          dataIndex: 'certificateNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '出生日期',
          dataIndex: 'birthday',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '省',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '县区',
          dataIndex: 'areaName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系地址',
          dataIndex: 'address',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
